package com.ara.common.kernel.dialog;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.lifecycle.Lifecycle;

import com.ara.common.kernel.base.BaseDialog;
import com.ara.common.kernel.databinding.DialogLoadingBinding;

/**
 * Created by XieXin on 2020/1/9.
 * 加载对话框
 */
public class LoadingDialog extends BaseDialog<DialogLoadingBinding> {
    private int textId;
    private String textString;

    public LoadingDialog(@NonNull Context context, Lifecycle lifecycle) {
        super(context, lifecycle);
        this.context = context;
    }

    public LoadingDialog(@NonNull Context context, Lifecycle lifecycle, @NonNull String text) {
        super(context, lifecycle);
        this.context = context;
        this.textString = text;
    }

    public LoadingDialog(@NonNull Context context, Lifecycle lifecycle, @StringRes int id) {
        super(context, lifecycle);
        this.context = context;
        this.textId = id;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(binding.getRoot());


        if (!TextUtils.isEmpty(textString)) binding.tvText.setText(textString);
        if (textId > 0) binding.tvText.setText(textId);

        setDialogWidth(getWindow(), getContext());

        setCancelable(false);
    }

    public void setContent(@StringRes int id) {
        if (binding != null) binding.tvText.setText(id);
    }

    public void setContent(@NonNull String text) {
        if (binding != null) binding.tvText.setText(text);
    }
}
